package com.travelsmart.client.apresentacao.model;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.travelsmart.client.apresentacao.controller.Observable;

import com.travelsmart.client.apresentacao.model.SmartHotelModel.LOAD_STATUS;

import com.travelsmart.client.bean.to.FilterInfoHotel;
import com.travelsmart.client.bean.to.HotelTO;
import com.travelsmart.client.control.HotelSmartServiceAsync;

public class HotelModel extends Observable<HotelTO> {
	private HotelTO hotelTO;




	public void obterDadosHotel(final FilterInfoHotel filterInfoHotel) {
		assert filterInfoHotel.getLinkSelection() != null;
		assert filterInfoHotel.getCodeHotel() != 0;
		assert filterInfoHotel.getArrivalDate() != null;
		assert filterInfoHotel.getDepartureDate() != null;
		SmartHotelModel.instance.getLoadModel().setLoad(LOAD_STATUS.LOADING);
		HotelSmartServiceAsync.service.dadosHotel(filterInfoHotel,
				new AsyncCallback<HotelTO>() {
					@Override
					public void onSuccess(HotelTO result) {
						SmartHotelModel.instance.getLoadModel().setLoad(LOAD_STATUS.DONE);
						setHotelTO(result);

					}

					@Override
					public void onFailure(Throwable caught) {
						SmartHotelModel.instance.getLoadModel().setLoad(LOAD_STATUS.DONE);
						SmartHotelModel.instance.getErroHotelModel().setErro(caught);
					}
				});

	}

	public HotelTO getHotelTO() {
		return hotelTO;
	}

	public void setHotelTO(HotelTO hotelTO) {
		this.hotelTO = hotelTO;
		super.setChanged();
		super.notifyObservers(hotelTO);
	}
}

